<?php
namespace app\common\validate;
use think\Validate;

class User extends Validate
{
    protected $rule = [
        'username'          => 'unique:user|username|min:4',
        'nickname'          => 'unique:user|nickname|min:2',
        'password'          => 'min:6',
        'mobile'            => 'unique:user|mobile',
        'email'             => 'email:user',
    ];
    protected $regex = [
        'usernameRegex'    => '^[a-zA-Z][A-Za-z0-9]+$'
    ];
    protected $message = [
    	'nickname.min'      => '昵称至少2位',
    	'username.min'      => '用户名至少4位',
        'nickname.unique'   => '昵称已存在',
        'username.unique'   => '用户名已存在',
        'password.length'   => '密码不小于6位',
        'username.usernameRegex'     => '用户名只能含有字母或数字且只能以字母开头',
        'email.email'       => '邮箱格式错误',
    ];

    protected $scene = [
        'add'   =>  ['nickname','email'],
        'edit'  =>  ['email'],
    ];
}